package com.adobe.utils
{
	
	/*
	
		trace(TimeFomatter.formatTime(0));
		trace(TimeFomatter.formatTime(1));
		trace(TimeFomatter.formatTime(59.9));
		trace(TimeFomatter.formatTime(60));
		trace(TimeFomatter.formatTime(1210));
		trace(TimeFomatter.formatTime(8252));
		
		trace("--------");
		
		trace(TimeFomatter.convertToNumber("00:00:00"));
		trace(TimeFomatter.convertToNumber("00:00:01"));
		trace(TimeFomatter.convertToNumber("00:00:59"));
		trace(TimeFomatter.convertToNumber("00:01:00"));
		trace(TimeFomatter.convertToNumber("00:20:10"));
		trace(TimeFomatter.convertToNumber("02:17:32"));
		
		trace("--------");
		
		trace(TimeFomatter.convertToNumber("23"));
		trace(TimeFomatter.convertToNumber("8:12"));	

	*/
	
	public class TimeFomatter
	{
		
		public static const HH_MM_SS:Number = 0;
		public static const MM_SS:Number = 1;
		
		
		/**
		 * 
		 * 초(sec)값을 받아 "hh:mm:ss" 또는 "mm:ss" 형식의 문자열 값을 반환<br>
		 * 
		 * @param type 
		 *    DateTime.HH_MM_SS 또는 DateTime.MM_SS (type값을 지정하지 않으면 "hh:mm:ss" 형식으로 반환)
		 *     
		 */
		public static function formatTime(sec:Number, type:Number = TimeFomatter.HH_MM_SS):String {
			sec = Math.floor(sec);
			
			var h:String = (Math.floor(sec / 3600)).toString();
			var m:String = (Math.floor((sec % 3600) / 60)).toString();
			var s:String = (sec % 60).toString();
			
			if (h.length == 1) h = "0" + h;
			if (m.length == 1) m = "0" + m;
			if (s.length == 1) s = "0" + s;
			
			
			if (type == TimeFomatter.HH_MM_SS)
				return h + ":" + m + ":" + s;
			else 
				return m + ":" + s;
		}

		
		public static function convertToNumber(val:String):Number {
			var result:Number = 0;
			var elements:Array = val.split(":");
			
			if (elements.length == 1)
				result = int(elements[0]);
			else if (elements.length == 2)
				result = int(elements[0]) * 60 + int(elements[1]);
			else if (elements.length == 3)
				result = int(elements[0]) * 3600 + int(elements[1]) * 60 + int(elements[2]);
			
			return result;
		}

		
		
	}
}